package leetcode.weekly.week304;

import java.util.Arrays;
import java.util.PriorityQueue;

//Solution1Test
public class Solution1 {

	public int minimumOperations(int[] nums) {
		Arrays.sort(nums);
		int ans = 0, sub = 0, num = 0;
		for (int i = 0; i < nums.length; i++) {
			if (sub < (num = nums[i])) {
				ans += 1;
				sub += num - sub;
			}
		}
		return ans;
	}

	public int minimumOperations1(int[] nums) {
		int ans = 0;
		PriorityQueue<Integer> queue = new PriorityQueue<>();
		for (int i = 0; i < nums.length; i++) {
			if (nums[i] != 0) {
				queue.add(nums[i]);
			}
		}
		while (!queue.isEmpty()) {
			int sub = queue.poll();
			ans += 1;
			PriorityQueue<Integer> tmp = new PriorityQueue<>();
			while (!queue.isEmpty()) {
				int cur = queue.poll() - sub;
				if (cur != 0)
					tmp.add(cur);
			}
			queue = tmp;
		}
		return ans;
	}

}
